//
//  ViewController.m
//  UI沙拉酱作业
//
//  Created by student on 16/2/23.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>
@property (nonatomic,strong) NSArray *leftList;
@property (nonatomic,strong) NSArray *rightList;
@property (nonatomic,strong) NSArray *list;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.pickView.dataSource = self;
    self.pickView.delegate = self;
    
    self.leftList = @[@"火腿",@"火鸡",@"花生酱",@"金枪鱼沙拉",@"鸡丁沙拉",@"烤牛肉"];
    self.rightList = @[@"白面包",@"粗面粉面包",@"黑麦面包",@"酸面包"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)btnPressed:(id)sender
{
    int sel1 = [self.pickView selectedRowInComponent:0];
    int sel2 = [self.pickView selectedRowInComponent:1];
    
    self.infoLabel.text =[NSString stringWithFormat:@"我的早饭是%@和%@",self.leftList[sel1],self.rightList[sel2]];
    
    
    // selectedRowInComponent得到PickerView第几列选中了第几项
   // int sel = [self.pickView selectedRowInComponent:0];// 第0列选择了几项
    NSString *name = [NSString stringWithFormat:@"您选择了%@和%@",self.leftList[sel1],self.rightList[sel2]];// 通过第几项
    
    //UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:[NSString stringWithFormat:@"您选择了%@和%@",self.leftList[sel1],self.rightList[sel2] delegate:nil cancelButtonTitle:@"重新选择"  otherButtonTitles:nil];
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"" message:name delegate:nil cancelButtonTitle:@"重新选择" otherButtonTitles:@"确定",nil];
    [alertView show];
}

#pragma mark -
// 有几列？
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}

// 第几列有几行?
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
    if(component == 0)
    {
        return self.leftList.count;
    }
    else
    {
        return self.rightList.count;
    }
}

// 第几行第几列是什么内容
- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if(component == 0)
    {
        return self.leftList[row];
    }
    else
    {
        return self.rightList[row];
    }
}


// 触发的事件
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if(component == 0)
    {
        NSLog(@"当前你选择了%@",self.leftList[row]);
    }
    else
    {
        NSLog(@"当前你选择了%@",self.rightList[row]);    }
}

@end
